package at.ac.univie.zsu.aguataplan.property;

import java.util.Locale;
import java.util.ResourceBundle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

/**
 * java standard i18n using in spring
 * 
 * @author gerry
 * 
 */
@Configurable
public class I18nProperties {

	@Autowired
	private UIProperties uiPropertiesId;

	private ResourceBundle messages;

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public I18nProperties() {
	}

	// ----------------------------------------------------
	// METHODS PRIVATE
	// ----------------------------------------------------

	@SuppressWarnings("unused")
	private void init() {
		Locale currentLocale;
		currentLocale = new Locale(uiPropertiesId.getLanguage(), uiPropertiesId.getCountry());

		messages = ResourceBundle.getBundle("etc.MessagesBundle", currentLocale);
	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	/**
	 * lookup in ResourceBundle
	 * 
	 * @param key
	 * @return
	 */
	public String getString(String key) {
		return messages.getString(key);
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public ResourceBundle getMessages() {
		return messages;
	}

	public UIProperties getUiPropertiesId() {
		return uiPropertiesId;
	}

	public void setUiPropertiesId(UIProperties uiPropertiesId) {
		this.uiPropertiesId = uiPropertiesId;
	}

	public void setMessages(ResourceBundle messages) {
		this.messages = messages;
	}

}
